﻿using B.S.Passport.Infacetrue;
using B.S.Passport.Domain;
using B.S.Passport.ErrorCode;
using B.S.Passport.Infacetrue;
using B.S.Passport.Write.API.Application;
using DAL;
using MediatR;



namespace B.S.Passport.Write.API.ApplicationHander
{
    public class DelwhouseCommandHander : IRequestHandler<DelwhouseCommand, ApiResult<object>>
    {
        public readonly IBaseRepository<WarehouseModel> WarehouseModelrepistory;
        public readonly DBHelper1 db;

        public DelwhouseCommandHander(IBaseRepository<WarehouseModel> warehouseModelrepistory, DBHelper1 dBHelper)
        {
            WarehouseModelrepistory = warehouseModelrepistory;
            this.db = dBHelper;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<object>> Handle(DelwhouseCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> apiResult = new ApiResult<object>();
            apiResult.Code = (ApiEnums)Renum.删除成功;
            apiResult.Message = Renum.删除成功.ToString();
            var sql = $"update WarehouseModel set isdelete=1 where WarehouseId='{request.WarehouseId}'";
            var ss = db.NonQuery(sql);
            if (ss > 0)
            {
                apiResult.Code = (ApiEnums)Renum.删除成功;
                apiResult.Message = Renum.删除成功.ToString();
                apiResult.Data = sql;
            }
            else
            {
                apiResult.Code = (ApiEnums)Renum.删除失败;
                apiResult.Message = Renum.删除失败.ToString();
                apiResult.Data = sql;
            }
            return Task.FromResult(apiResult);
            
        }
    }
}
